package com.usefullc.user.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.user.domain.Tenant;
import com.usefullc.user.mapper.TenantMapper;
import com.usefullc.user.query.TenantQuery;
import com.usefullc.user.vo.TenantVo;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.service.AbstractBizService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 租户服务类
 * @author: 星空
 * @date: 2022-09-01
 */
@Service
public class TenantService extends AbstractBizService<TenantMapper, Tenant, TenantQuery> {


    @Override
    protected QueryWrapper<Tenant> getQueryWrapper(TenantQuery query) {
        QueryWrapper<Tenant> queryWrapper = super.getQueryWrapper(query);
        return queryWrapper;
    }

    public Pager<TenantVo> findVoByPage(TenantQuery query){
        Pager<Tenant> page = this.findByPage(query);
        Pager<TenantVo> newPage = new Pager<>(page);
        List<Tenant> dataList = page.getDataList();
        List<TenantVo> newDataList = new ArrayList<>();
        newPage.setDataList(newDataList);
        for (Tenant tenant : dataList) {
            TenantVo tenantVo = BeanUtils.beanCopy(tenant, TenantVo.class);
            newDataList.add(tenantVo);
        }
        return newPage;
    }


}
